//
//  ECUIVC_Material.m
//  Edu_iOS
//
//  Created by yanyan on 2017/9/19.
//  Copyright © 2017年 yanyan. All rights reserved.
//

#import "ECUIVC_Material.h"
#import "CYUITVDSD_base.h"
#import "CYUITVDSDBridge.h"
#import "ECUITVCell_DetailMaterial.h"
extern CGFloat TABBAR_FOOTER_HEIGHT;

@interface ECUIVC_Material ()<UITableViewDelegate,UITableViewDataSource>
//@property(nonatomic,strong)UITableView *tableView;
@property(nonatomic,strong)NSMutableArray *dataSource;
@end

@implementation ECUIVC_Material
@synthesize tableView = _tableView;
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
}

-(void)addSubviews
{
    [super addSubviews];
    [self.view addSubview:self.tableView];
    [self initDataSource];
    UIView *headerView = [[UIView alloc] initWithFrame:(CGRect){0, 0, kScreenWidth, TABLEVIEWCONTENT_OFFSET_Y}];
   _tableView.tableHeaderView = headerView;
    _tableView.tableFooterView = [[UIView alloc]init];
}
- (void) initDataSource{
    _dataSource = [[NSMutableArray alloc]init];
    for (int i = 0; i < 10; i ++) {
        ECModel_DetailMaterial *mo = [[ECModel_DetailMaterial alloc]init];
        mo.name = [NSString stringWithFormat:@"课时 %d 部分课件解析", i];
        mo.size = @"2.3MB";
        NSArray *tags = @[@"ppt",@"pdf",@"word",@"excel"];
        mo.tag = tags[rand() % 4];
        [_dataSource addObject:mo];
    }
}
- (UITableView *)tableView
{
    if (!_tableView) {
        _tableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, kScreenWidth, kScreenHeight -TABBAR_TITLE_HEIGHT - 64 - TABBAR_FOOTER_HEIGHT) style:UITableViewStylePlain];
        [_tableView registerClass:[ECUITVCell_DetailMaterial class] forCellReuseIdentifier:@"cell"];
        _tableView.backgroundColor = [[UIColor randomColor] colorWithAlphaComponent:0.3];
        _tableView.delegate = self;
        _tableView.dataSource = self;
        _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
//        _tableView.exclusiveTouch = YES;
       
    }
    return _tableView;
}
- (void)tableViewDidScroll:(tableViewDidScrollBlock)scrollBlock {
    self.scrollBlock = scrollBlock;
}
- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
    self.scrollBlock(scrollView.contentOffset.y);
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return _dataSource.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    ECUITVCell_DetailMaterial *cell = [tableView dequeueReusableCellWithIdentifier:@"cell" forIndexPath:indexPath];
    cell.object = [_dataSource objectAtIndex:indexPath.row];
    return cell;
}
//- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
//{
//    UIView *view = [[UIView alloc]init];
//    view.backgroundColor = [UIColor colorWithHexString:@"#f2f5f6"];
//
//    return view;
//}
//- (CGFloat) tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
//    
//    return 5;
//}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 80;
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
